package me.aartikov.advancedscreenswitchersample.ui;


import me.aartikov.advancedscreenswitchersample.SampleApplication;
import me.aartikov.advancedscreenswitchersample.ResourceTable;
import me.aartikov.advancedscreenswitchersample.screens.InnerScreen;
import me.aartikov.alligator.util.Log;
import me.aartikov.alligator.Navigator;
import me.aartikov.alligator.helpers.MiFraction;
import me.aartikov.alligator.annotations.RegisterScreen;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;


@RegisterScreen(InnerScreen.class)
public class InnerMiFraction extends MiFraction {
    Text mCounterTextView;

    Button mForwardButton;


    private Navigator mNavigator = SampleApplication.getNavigator();

    public InnerMiFraction() {

    }

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Log.i("onComponentAttached([scatter, container, intent]):26");
        Component component = scatter.parse(ResourceTable.Layout_fragment_inner, null, false);
        InnerScreen screen = SampleApplication.getScreenResolver().getScreen(this);
        int counter = screen.getCounter();
        mCounterTextView = (Text) component.findComponentById(ResourceTable.Id_counter_text_view);
        mCounterTextView.setText(getFractionAbility().getString(ResourceTable.String_counter_template, counter));
        mForwardButton = (Button) component.findComponentById(ResourceTable.Id_forward_button);
        mForwardButton.setClickedListener(v -> mNavigator.goForward(new InnerScreen(counter + 1, ResourceTable.Id_inner_container, screen.getGroup())));

        return component;
    }



    @Override
    protected void setInitialFragmentIfRequired() {

    }


}